package fenetres;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class Utilisateur extends JFrame implements ActionListener {
  /**
	 * 
	 */
  private static final long serialVersionUID = 1L;
    JPanel pane, imgPanel;
	JLabel NomUserLbl;
	JLabel PreUserLbl;
	JLabel NumTelLbl;
	JLabel MailUserLbl;
	JLabel LogUserLbl;
	JLabel PassWdLbl;
	JLabel label;
	
	JTextField nomTxt;
	JTextField prenomtTxt;
	JTextField numTelTxt;
	JTextField mailTxt;
	JTextField  logTxt;
	JTextField pwdTxt;
	
	JButton validerBut, annulerBut,fermerBut;
	
  public Utilisateur() {
	  
	  jbInit();
      Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 
	  this.setLocation((screen.width - this.getSize().width)/2,(screen.height - this.getSize().height)/2);
	  this.setLocationRelativeTo(null);
	  this.getContentPane().add(pane);
	  this.setSize(700,350);
	  this.setTitle("Compte Utilisateur");
	  this.setVisible(true);
	  this.setBackground(Color.white);
	  this.setDefaultCloseOperation(HIDE_ON_CLOSE);	
	  this.setLocationRelativeTo(null);
//			imagePanel = new JPanel();
//			imagePanel.setBounds(0, 0, 600, 550);

  }
  public void jbInit()  {
	  pane = new JPanel();
   	  pane.setSize(700,350);
	  pane.setLayout(null);
	  ImageIcon background = new ImageIcon("image/User1.jpeg");
	  JLabel label = new JLabel();
	  label.setIcon(background);
	  
	  JLabel NomUserLbl= new JLabel (" Nom Utilisateur (*)");
	  NomUserLbl.setForeground(Color.blue); 
	  nomTxt=new JTextField();
	  JLabel PreUserLbl= new JLabel (" Prenom Utilisateur (*)");
	  PreUserLbl.setForeground(Color.blue);
	  prenomtTxt= new JTextField();
	  JLabel NumTelLbl=new JLabel (" Numero Telephone ");
	  NumTelLbl.setForeground(Color.blue);
	  numTelTxt=new JTextField();
	  JLabel MailUserLbl= new JLabel (" Mail Utilisateur ");
	  MailUserLbl.setForeground(Color.blue);
	  mailTxt=new JTextField();
	  JLabel LogUserLbl= new JLabel (" Login Utilisateur (*)");
	  LogUserLbl.setForeground(Color.blue);
	  logTxt = new JTextField();
	  JLabel PassWdLbl= new JLabel (" Mot de passe (*)");
      PassWdLbl.setForeground(Color.blue);
      pwdTxt=new JTextField();
      annulerBut = new JButton("Annuler");
	  validerBut = new JButton("Valider");
	  fermerBut = new JButton("Fermer");
      
      
	  fermerBut.setText("Fermer");
	  fermerBut.addActionListener(this);
	  annulerBut.setText("Annuler");
	  annulerBut.addActionListener( (ActionListener) this);
	  validerBut.setText("Valider");
	  validerBut.addActionListener((ActionListener) this);
	
	  
	  pane.add(NomUserLbl);
	  pane.add(nomTxt);
	  pane.add(PreUserLbl);
	  pane.add(prenomtTxt);
	  pane.add(NumTelLbl);
	  pane.add(numTelTxt);
	  pane.add(MailUserLbl);
	  pane.add(mailTxt);
	  pane.add(LogUserLbl);
	  pane.add(logTxt);
	  pane.add(PassWdLbl);
	  pane.add(pwdTxt);
	  pane.add(validerBut);
	  pane.add(annulerBut);
	  pane.add(fermerBut);
      pane.add(label);
      
      label.setBounds(550, 0, 150,120);
	  NomUserLbl.setBounds(5,15,170,25);
	  nomTxt.setBounds(190,15,250,25);
	  PreUserLbl.setBounds(5,50,170,25);
	  prenomtTxt.setBounds(190,50,250,25);
	  NumTelLbl.setBounds(5,85,170,25);
	  numTelTxt.setBounds(190,85,250,25);
	  MailUserLbl.setBounds(5,120,170,25);
	  mailTxt.setBounds(190,120,250,25);
	  LogUserLbl.setBounds(5,155,140,25);
	  logTxt.setBounds(190,155,250,25);
	  PassWdLbl.setBounds(5, 190, 270, 25);
	  pwdTxt.setBounds(190, 190, 250, 25);
	  
	  validerBut.setBounds(155,240,100,25);
	  fermerBut.setBounds(280,240,100,25);
	  annulerBut.setBounds(400,240,100,25);	
  }
  
  public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getSource() == fermerBut){
			this.dispose();
		}
		if (e.getSource()==annulerBut){
				 nomTxt.setText("");
				 prenomtTxt.setText("");
				 numTelTxt.setText("");
				 mailTxt.setText("");
				 logTxt.setText("");
				 pwdTxt.setText("");
			}
		if (e.getSource()==validerBut){
		validerBut_actionPerformed();
		}
		

}
private void validerBut_actionPerformed() {
	// TODO Auto-generated method stub
	boolean etat = true;
	if((nomTxt.getText().isEmpty()) || (prenomtTxt.getText().isEmpty()) ||(logTxt.getText().isEmpty()) || (pwdTxt.getText().isEmpty()))
	{
		etat = false;
		
		JOptionPane.showMessageDialog (null, "Les champs obligatoires ne sont pas remplis !", "Information", JOptionPane.WARNING_MESSAGE) ;
	}
	
	if((nomTxt.getText().contains("\"")) || (nomTxt.getText().contains("\'")) || (nomTxt.getText().contains("\\")) || (nomTxt.getText().contains("%")))
	{
			JOptionPane.showMessageDialog (null, "Les champs ne doivent pas contenir les caractères spéciaux !", "Information", JOptionPane.WARNING_MESSAGE) ;
			 etat = false;;
		}
	
	 if (etat) { //la saisie est juste
	        int result=JOptionPane.showConfirmDialog(null,"Voulez vous vraiment valider ces informations","Confirmation ajout",JOptionPane.YES_NO_OPTION);
	        if(result==0){//reponse oui
	        	
	        //Commentaire = new Commentaire1();
	        	nomTxt.setText("");
	        	logTxt.setText("");
	        	pwdTxt.setText("");
	        	prenomtTxt.setText("");
	  
	        }
}
}
	
}

